package com.rpa.server.servicerpaserver.crawler.controller;

import com.rpa.secure.servicerpasecure.common.constant.MessageConstant;
import com.rpa.secure.servicerpasecure.common.exception.TaskException;
import com.rpa.secure.servicerpasecure.common.util.CurrentTeacherInfoUtil;
import com.rpa.server.servicerpaserver.crawler.entity.dto.WorkDto;
import com.rpa.server.servicerpaserver.crawler.operate.WorkOperate;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName WorkController
 * @Description TODO
 * @Author 86152
 * @Date 2025/2/4 16:33
 * @Version 1.0
 **/
@Tag(name = "获取成绩信息相关接口", description = "WorkCrawlerController")
@Slf4j
@RestController
@RequestMapping("/crawler")
public class WorkCrawlerController {
    @Autowired
    private WorkOperate workOperate;

    @PostMapping("/getWork")
    @Operation(summary = "获取成绩信息", description = "getWork")
    public Boolean getActive(@RequestBody WorkDto work) {
        if (work == null) {
            log.error("请求体中的 user 对象为空");
            throw new TaskException(MessageConstant.INVALID_REQUEST_BODY);
        }
        String rpaRegisterId = work.getAccountId();

        // 检查 rpaRegisterId 是否为空
        if (rpaRegisterId == null) {
            log.error("请求体中的 rpaRegisterId 字段为空");
            throw new TaskException(MessageConstant.INVALID_REQUEST_BODY);
        }

        log.info("当前用户id为：{}", CurrentTeacherInfoUtil.getCurrentTeacherId());
        log.info("接收到的 rpaRegisterId 为：{}", rpaRegisterId);
        return workOperate.getWork(work).join();
    }
}
